package com.cqie.practicaltraining.controller;

import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.dto.AddUserDto;
import com.cqie.practicaltraining.dto.SelectDto;
import com.cqie.practicaltraining.dto.UpdateUserDto;
import com.cqie.practicaltraining.service.impl.UserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/user")
@Api("用户管理")
public class userController {
    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/getUserPageByCondition")
    @ApiOperation(value = "条件查询用户信息")
    public R getUserPageByCondition(@RequestBody @Validated SelectDto selectDto) {
        return userService.getUserPageByCondition(selectDto);
    }

    @PostMapping("/addUser")
    @ApiOperation(value = "添加用户")
    public R addUser(@RequestBody @Validated AddUserDto addUserDto) {
        return userService.addUser(addUserDto);
    }

    @PutMapping("/updateUser")
    @ApiOperation(value = "修改用户信息")
    public R updateUser(@RequestBody @Validated UpdateUserDto users) {
        return userService.updateUser(users);
    }

    @PutMapping("/changeUserStatus")
    @ApiOperation(value = "修改用户状态")
    public R changeUserStatus(@RequestParam Integer userId) {
        return userService.changeUserStatus(userId);
    }
}
